<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<img id="img" src="" alt="">
<p></p>
<button id="pre">pre</button>
<button id="next">next</button>
<script>
    window.onload = function () {

        //get element
        var icon = document.getElementById("img");
        var pre = document.getElementById("pre");
        var next = document.getElementById("next");


        //watch btn click
        var minIndex = 1,maxIndex = 3,currentIndex = minIndex;
        pre.onclick = function () {
            console.log("click pre img");
            if (currentIndex === minIndex){
                currentIndex = minIndex ;

            }
            else
            {
                currentIndex --  ;
            }
            icon.setAttribute("src",currentIndex + ".jpg");
        };
        next.onclick = function () {
            console.log("click next img");
            if (currentIndex === maxIndex){
                currentIndex = minIndex;

            }
            else
            {
               currentIndex ++ ;
            }
            icon.setAttribute("src",currentIndex + ".jpg");

        }
        //
    }
</script>
</body>
</html>